<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/20/020
 * Time: 10:32
 */

namespace App\Model;




use lib\Model;

class BlogModel extends Model
{
    private $table = 'blog';
    private $pk = 'bid';
    public function checkimg(Array $files)
    {   $blogsrcs=[];
        $count = count($files['name']);
        $types = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
        $uploadDir = 'upload' . DIRECTORY_SEPARATOR;
        for ($i = 0; $i < $count; $i++) {
            // 处理上传图片文件
            if ($files['error'][$i] == 0) {
                if (in_array($files['type'][$i], $types)) {
                    if (($files['size'][$i] > 0) && ($files['size'][$i] < 5 * 1024 * 1024)) {

                        $fileName = md5(mt_rand() . time() . $files['name'][$i]);
                        $imageid = md5($fileName);
                        // 上传文件相对于public的相对路径
                        $filePath = $uploadDir . $fileName . '.' . pathinfo($files['name'][$i])['extension'];
                        //echo $filePath;exit();
                        // 上传文件的绝对路径
                        $destination = PUBLIC_DIR . DIRECTORY_SEPARATOR . $filePath;
                        move_uploaded_file($files['tmp_name'][$i], $destination);
                        // 上传成功之后，构建图片Image对象
                        $filePaths=str_replace('\\','/', $filePath);
                       $blogsrcs[]=$filePaths;

                    }
                }
            }
        }
       // print_r($blogsrcs);exit();
        $char = implode(";", $blogsrcs);
        //echo $char;exit();
       return $char;
    }

}